<template>
  <back-btn></back-btn>
  <div id="app">
    <h2>msg: {{ msg }}</h2>
    <button @click="updateMsg">更新msg</button>

    <button @click="goKeepAliveCom">前往缓存组件</button>
  </div>
</template>

<script lang="ts">
import {
  ref,
  defineComponent,
  onBeforeMount,
  onBeforeUnmount,
  onBeforeUpdate,
  onMounted,
  onUnmounted,
  onUpdated,
} from "vue";
import { useRouter } from "vue-router";

export default defineComponent({
  setup() {
    const msg = ref("温情");

    const updateMsg = () => {
      msg.value += "K";
    };

    const router = useRouter();

    const goKeepAliveCom = () => {
      router.push("/keepAlive");
    };

    onBeforeMount(() => {
      console.log("onBeforeMount-组件挂载到节点之前");
    });

    onMounted(() => {
      console.log("onMounted-组件挂载完成后");
    });

    onBeforeUpdate(() => {
      console.log("onBeforeUpdate-组件更新之前");
    });

    onUpdated(() => {
      console.log("onUpdated-组件更新完成之后");
    });

    onBeforeUnmount(() => {
      console.log("onBeforeUnmount-组件卸载之前");
    });

    onUnmounted(() => {
      console.log("onUnmounted-组件卸载完成");
    });

    console.log("setup-开始创建组件之前");

    return {
      msg,
      updateMsg,
      goKeepAliveCom,
    };
  },
});
</script>

<style scoped></style>
